package com.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LookingAtAndMatches {

	public static void main(String[] args) {
		String content = "It's my life, hero you are, no hero, wings you are the hero~";
		Pattern p = Pattern.compile("\\w*o");
		Matcher m = p.matcher(content);
		while (m.find()) {
			System.out.println("find(): " + m.group() + " start at "
					+ m.start() + " end at " + (m.end() - 1));
		}
		if (m.lookingAt()) {
			System.out.println("lookingAt(): " + m.group() + " start at "
					+ m.start() + " end at " + (m.end() - 1));
		}
		if (m.matches()) {
			System.out.println("matches(): " + m.group() + " start at "
					+ m.start() + " end at " + (m.end() - 1));
		}

		// 尝试将从区域开头开始的输入序列与该模式匹配
		p = Pattern.compile("\\w*'");
		m = p.matcher(content);
		if (m.lookingAt()) {
			System.out.println("lookingAt(): " + m.group() + " start at "
					+ m.start() + " end at " + (m.end() - 1));
		}

		// 尝试将整个区域与模式匹配
		p = Pattern.compile("\\w*.+~");
		m = p.matcher(content);
		if (m.matches()) {
			System.out.println("matches(): " + m.group() + " start at "
					+ m.start() + " end at " + (m.end() - 1));
		}
	}

}
